def load(bearing,weights,values):
    candidates=[ weight for weight in weights if weight <= bearing ]
    n=len(candidates)
    benefits=values[:n]
    if bearing in candidates:
        return benefits[candidates.index(bearing)]
    candidate=lambda x:benefits[x]+\
                       load(bearing-candidates[x],
                            candidates[:x]+candidates[x+1:],
                            benefits[:x]+benefits[x+1:])
    result=0
    for i in range(n):
        result=max(result,candidate(i))
    return result

weights=[1,2,5,6,7]
values=[1,6,18,22,28]
print(load(11,weights,values))
